<?php
// 指定允许其他域名访问  
header('Access-Control-Allow-Origin:*');
// 响应类型  
header('Access-Control-Allow-Methods:POST');
// 响应头设置  
header('Access-Control-Allow-Headers:x-requested-with,content-type:application/json,charset:utf-8');
class Login extends CI_Controller{
    public function __construct(){

        parent::__construct();
        $this->load->model('Users/User_model');
        $this->load->helper('url_helper');
        $this->load->library('session');
        // $this->load->helper('date');
        $this->load->helper(array('form', 'url', 'date'));
    }

    //用户登录
    public function login(){

        $username = $_POST['username'];//账号
        $password = $_POST['password'];//密码

        // $username = "IT00055";
        // $password = "123";

        $result_json = $this->User_model->validUserLogin(
            $username,
            $password
        );

        echo $result_json;

        return 0;
    }

    //密码修改
    public function password_update(){
        $username = $_POST['username'];//账号
        $password = $_POST['password'];//密码

        // $username = "IT00055";
        // $password = "123456780";

        $result_json = $this->User_model->password_update(
            $username,
            $password
        );

        echo $result_json;

        return 0;
    }

    //账号删除
    public function user_delete(){
        $username = $_POST['username'];//账号
        $admname  = $_POST['admname']; //管理员账号

        // $username = "IT";//账号
        // $admname = "A001"; //管理员账号

        $result_json = $this->User_model->user_delete(
            $username,
            $admname
        );

        echo $result_json;

        return 0;
    }
}
